#include <sys/types.h>
#include <functional>
#include <string.h>
#include <stdio.h>
using namespace std;

#include "error.h"
#include "utility.h"
#include "catalog.h"

// define if debug output wanted


//
// Retrieves and prints information from the catalogs about the for the
// user. If no relation is given (relation is NULL), then it lists all
// the relations in the database, along with the width in bytes of the
// relation, the number of attributes in the relation, and the number of
// attributes that are indexed.  If a relation is given, then it lists
// all of the attributes of the relation, as well as its type, length,
// and offset, whether it's indexed or not, and its index number.
//
// Returns:
// 	OK on success
// 	error code otherwise
//

const Status RelCatalog::help(const string & relation)
{
  Status status;
  RelDesc rd;
  AttrDesc *attrs;
  int attrCnt;

  if (relation.empty()) return UT_Print(RELCATNAME);

  // get relation data
  status = relCat->getInfo(relation, rd);
  if (status != OK) return status;

  // start insertFileScan on relation
  status = attrCat->getRelInfo(relation, attrCnt, attrs);
  if (status != OK) return status;

  cout << "relation: " << rd.relName << "   attrCnt: " << rd.attrCnt << endl;

  for (int i = 0; i < attrCnt; i++)
  {

    string atype;
    switch(attrs[i].attrType)
    {
      case STRING: 
        atype = "string";
        break;
      case INTEGER: 
        atype = "int";
        break;
      case FLOAT: 
        atype = "float";
        break;
      default: 
        atype = "n/a";
        break;
    }


     cout << "attribute: " << attrs[i].relName;
     cout << ",   type: " << atype;
     cout << ",   length: " << attrs[i].attrLen;
     cout << ",   offset: " << attrs[i].attrOffset;
     // index???
     cout << endl;

  }
   
  delete attrs;

  return OK;
}
